﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCePart.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFCePart
//
// -------------------------------------------------------------------------

#include "NFCePart.h"

#include "proto_cs_login.pb.h"
#include "proto_db.pb.h"
#include "NFComm/NFPluginModule/NFMathOp.h"

NFCePart::NFCePart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFCePart::~NFCePart()
{
}

int NFCePart::CreateInit()
{
    return 0;
}
    
int NFCePart::ResumeInit()
{
    return 0;
}

int NFCePart::LoadFromDB(const proto_ff::tbRoleDetail *pDBData)
{
    m_stData.FromPb(pDBData->role_play_data().ce_data());
    return 0;
}

int NFCePart::InitConfig(proto_ff::tbRoleDetail *pDbData, const RoleOne &stRoleOne)
{
    pDbData->mutable_role_play_data()->mutable_ce_data();
    return 0;
}

int NFCePart::SaveDB(proto_ff::tbRoleDetail *pDBData)
{
    m_stData.ToPb(pDBData->mutable_role_play_data()->mutable_ce_data());
    return 0;
}

int NFCePart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    m_stData.ToPb(pCSGetRoleRsp->mutable_ce_data());
    return 0;
}

int NFCePart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    return 0;
}

int NFCePart::SetData(const proto_ff::RoleCEData* pRoleCEData)
{
    CHECK_NULL(0, pRoleCEData);

    m_stData.FromPb(*pRoleCEData);
    return 0;
}

bool NFCePart::IsGetReward(int iIdx)
{
    auto iter = m_stData.get_reward_list.find(iIdx);
    if (iter != m_stData.get_reward_list.end())
    {
        return true;
    }
    return false;
}

int NFCePart::SetGetReward(int iIdx)
{
    auto iter = m_stData.get_reward_list.find(iIdx);
    if (iter != m_stData.get_reward_list.end())
    {
        return 0;
    }

    CHECK_EXPR(m_stData.get_reward_list.full(), -1, "get_reward_list full:{}", m_stData.get_reward_list.size());
    m_stData.get_reward_list.insert(iIdx);
    return 0;
}

int NFCePart::SetCE(proto_ff::enCEType eType, int64_t llCE)
{
    CHECK_EXPR(proto_ff::enCEType_IsValid(eType), -1, "invalid type:{}", eType);
    CHECK_EXPR(eType >= 0 && eType < (int)ARRAYSIZE(m_stData.ce_list), -1, "invalid type:{}", eType);

    m_stData.ce_list[(int)eType] = llCE;
    MarkDirty();

    return 0;
}
